﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;

namespace TwoPageView3 {
    class Utility {
        private Utility() { }

        public static Size DevicePixelToSize(Visual visual, Size px) {
            var source = PresentationSource.FromVisual(visual);
            var size = source.CompositionTarget.TransformFromDevice.Transform((Vector)px);
            return new Size(size.X, size.Y);
        }

        public static Size SizeToDevicePixel(Visual visual, Size size) {
            var source = PresentationSource.FromVisual(visual);
            var px = source.CompositionTarget.TransformToDevice.Transform((Vector)size);
            return new Size(px.X, px.Y);
        }

        public static Size Union(Size lhs, Size rhs) {
            double w = (lhs.Width  < rhs.Width)  ? rhs.Width  : lhs.Width;
            double h = (lhs.Height < rhs.Height) ? rhs.Height : lhs.Height;
            return new Size(w, h);
        }
    }
}
